package cn.fl.product.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.fl.system.service.ISysDictionaryService;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.service.ICapPayInfoService;
import cn.fl.capital.vo.CapPayInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.product.service.ISplCrLimService;
import cn.fl.product.service.ISplInfoService;
import cn.fl.product.service.ISplRlPsnService;
import cn.fl.product.vo.PrjSplCrLimVO;
import cn.fl.product.vo.SplCrLimVO;
import cn.fl.product.vo.SplInfoVO;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.condition.PrjSplCrLimQueryCondition;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import cn.fl.system.constant.SysLogConstant;
import fl.spl.facade.spl.condition.SplCrLimQueryCondition;
import fl.spl.facade.spl.condition.SplInfoQueryCondition;
import fl.spl.facade.spl.dto.SplCrLimDTO;

/**
 * @Description: 供应商信息表 控制层
 */
@Controller
@RequestMapping("/product/splCrLim")
public class SplCrLimController extends BaseController {

	/**
	 * PrdSplInfo 服务层BEAN
	 */
	@Autowired
	private ISplInfoService prdSplInfoService;
	
	/**
	 * prdSplCrLim 服务层BEAN
	 */
	@Autowired
	private ISplCrLimService splCrLimService;
	
	/**
	 * 本地数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	@Autowired
	private ISysDictionaryService sysDictionaryService;
	
	@Autowired
	private ISplRlPsnService splRlPsnService;
	
	@Autowired
	private ICapPayInfoService capPayInfoService;
	
	/**
	 * 到项目授信列表页
	 */
	@RequestMapping(value="/toPrjSplCrLimListPage.do",method = { RequestMethod.GET})
	public ModelAndView toPrjSplCrLimListPage(HttpServletRequest request, HttpServletResponse response) {
		String mfrId = request.getParameter("mfrId");
		ModelAndView view = new ModelAndView("product/splCrLim/prjSplCrLimList");
		view.addObject("mfrId", mfrId);
		String limId = request.getParameter("limId");
		view.addObject("limId",limId);
//		//获取下拉列表数据
//		//审核状态
//		List<KeyValueVO> searchAudStsCdList = this.prdSplInfoService.searchAudStsCdList();
//		view.addObject("searchAudStsCdList", searchAudStsCdList);
//		//事业部
//		List<KeyValueVO> searchBuOrgList = this.prdSplInfoService.searchBuOrgCdList();
//		view.addObject("searchBuOrgList", searchBuOrgList);
		return view;
	}
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		String mfrId = request.getParameter("mfrId");
		ModelAndView view = new ModelAndView("product/splCrLim/prdSplCrLimList");
		view.addObject("mfrId", mfrId);
		
		//获取下拉列表数据
		//审核状态
		List<KeyValueVO> searchAudStsCdList = this.prdSplInfoService.searchAudStsCdList();
		view.addObject("searchAudStsCdList", searchAudStsCdList);
		//事业部
		List<KeyValueVO> searchBuOrgList = this.prdSplInfoService.searchBuOrgCdList();
		view.addObject("searchBuOrgList", searchBuOrgList);
		return view;
	}
	
	/**
	 * 初始化授信列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/crInitList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object crInitList(HttpServletRequest request, HttpServletResponse response) {
		//String mfrId = request.getParameter("mfrId");
		
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		Pager page = new Pager();
//		if (StringUtils.isNotEmpty(currentPage)) {
//			page.setCurrentPage(Integer.parseInt(currentPage));
//		}
//
//		if (StringUtils.isNotEmpty(pageSize)) {
//			page.setEveryPage(Integer.parseInt(pageSize));
//		}

		SplCrLimQueryCondition qc = new SplCrLimQueryCondition();
		//TODO 设置查询条件？
		String splId = request.getParameter("splId");
		if (StringUtils.isNotEmpty(splId)) {
			qc.setSplId(Long.valueOf(splId));
		}
		page.setCondition(qc);

		BaseLogUtils.newWebLogger("初始化SplCrLim列表页面数据.DATA:"+JSONObject.toJSONString(page))
				.setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		//Pager pager = this.splCrLimService.searchListPage(page);
		List<SplCrLimVO> list = splCrLimService.searchList(qc);
		//List<SplCrLimVO> list = (List<SplCrLimVO>) pager.getResultList();
		int pageNo =0;
		if(CollectionUtils.isNotEmpty(list)){
			pageNo = list.size();
		}
		ListPageVO<SplCrLimVO> listPage = new ListPageVO<SplCrLimVO>(list, pageNo);
		return listPage;
	}
	/**
	 * 初始化授信使用情况列表 initPrjSplCrLimList
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initPrjSplCrLimList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initPrjSplCrLimList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String mfrId = request.getParameter("mfrId");
		
		String limId = request.getParameter("limId");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjSplCrLimQueryCondition qc = new PrjSplCrLimQueryCondition();
		if (StringUtils.isNotBlank(limId)) {
			qc.setLimId(Long.parseLong(limId));
		}		
		page.setCondition(qc);
		BaseLogUtils.newWebLogger("初始化供应商列表页面数据.DATA:"+JSONObject.toJSONString(page))
				.setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		Pager pager = this.splCrLimService.serchPrjListPage(page);
		List<PrjSplCrLimVO> list = (List<PrjSplCrLimVO>) pager.getResultList();
		ListPageVO<PrjSplCrLimVO> listPage = new ListPageVO<PrjSplCrLimVO>(list, pager.getTotalCount());
		return listPage;
	}
	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initSplList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String mfrId = request.getParameter("mfrId");
		
		String splNm = request.getParameter("splNm");
		String audStsCd = request.getParameter("audStsCd");
		String buOrgCd = request.getParameter("buOrgCd");
		String splIdString = request.getParameter("splIdString");//报价方案属性配置中配置的供应商IDS
		
		String flag = request.getParameter("flag");//被引用为下拉框数据标识 (方案配置属性)
		String condition = request.getParameter("condition");
		String searchflag = request.getParameter("searchflag");

		String isEncrypt = request.getParameter("isEncrypt");

		String value = "";
		if(StringUtils.isNotBlank(condition)){
			String con = condition.substring(1, condition.length()-1);
			if(StringUtils.isNotBlank(con)){
				net.sf.json.JSONObject fromObject = net.sf.json.JSONObject.fromObject(con);
				value = (String) fromObject.get("value");
			}
		}
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		SplInfoQueryCondition qc = new SplInfoQueryCondition();
		if (StringUtils.isNotBlank(mfrId)) {
			qc.setMfrId(Long.valueOf(mfrId));
		}
		if (StringUtils.isNotBlank(splNm)) {
			qc.setSplNm(splNm);
		}
		if (StringUtils.isNotBlank(audStsCd)) {
			qc.setAudStsCd(audStsCd);
		}
			if (StringUtils.isNotBlank(buOrgCd)) {
				qc.setBuOrgCd(buOrgCd);
			}
		
		if (StringUtils.isNotEmpty(flag)) {
			if(StringUtils.isEmpty(value)&&StringUtils.isEmpty(splIdString)){//被引用为下拉框却没有查询条件返回null
				return null;
			}
			page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			//qc.setAudStsCd(BaseConstant.FLOW_CHECK_STATE_PASS);//审核通过
		}
		if (StringUtils.isNotEmpty(value)) {
			qc.setSplNm(value.trim());
		}else if(StringUtils.isNotEmpty(splIdString)){
			String[] strings = splIdString.trim().split(";");
			List<Long> splIds = new ArrayList<Long>();
			for (String string : strings) {
				splIds.add(Long.valueOf(string));
			}
			qc.setIds(splIds);
		}

		//判断查询条件 如果查询条件都为空  设置事业部的默认查询条件
		if(StringUtils.isBlank(splNm)&&StringUtils.isBlank(audStsCd)&&StringUtils.isBlank(buOrgCd)&&StringUtils.isBlank(searchflag)){
			/**
			 * 如果是事业部人员登录 加默认事业部查询条件 
			 */
			String currentBuOrgCd = CurrentThreadContext.getCurrentBuOrgCd();
			Map<String, String> buOrgCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_SYS_BU_ORG_CD);
			if(buOrgCdMap.containsKey(currentBuOrgCd)){
				qc.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			}
			/*SysOrgDTO orgDTO = this.sysOrgApiService.selectSysOrgByOrgCd(CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
			if(orgDTO.getOrgTypCd().equals(SysOrgConstant.SYS_ORG_ORG_TYP_CD_IS_BUSI)){
				qc.setBuOrgCd(orgDTO.getOrgCd());
			}*/
		}
		page.setCondition(qc);

		BaseLogUtils.newWebLogger("初始化供应商列表页面数据.DATA:"+JSONObject.toJSONString(page))
				.setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		Pager pager = null;
		if (StringUtils.isNotEmpty(isEncrypt) && BaseConstant.IS_YESNO_YES_STR.equals(isEncrypt)) {
			String roleisEncrypt = this.sysDictionaryService.getRoleisEncrypt();
			if (BaseConstant.IS_YESNO_YES_STR.equals(roleisEncrypt)) {
				pager = this.prdSplInfoService.searchListPageWithEncrypt(page);
			} else {
				pager = this.prdSplInfoService.searchListPage(page);
			}
		} else {
			pager = this.prdSplInfoService.searchListPage(page);
		}
		List<SplInfoVO> list = (List<SplInfoVO>) pager.getResultList();
		ListPageVO<SplInfoVO> listPage = new ListPageVO<SplInfoVO>(list, pager.getTotalCount());
		return listPage;
	}

	/**
	 * 到供应商授信页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toAddSplCrLimPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddSplCrLimPage(HttpServletRequest request, HttpServletResponse response) {
		String mfrId = request.getParameter("mfrId");
		String splId = request.getParameter("splId");
		//事业部
		List<KeyValueVO> searchBuOrgList = this.prdSplInfoService.searchBuOrgCdList();
		//授信类型
		List<KeyValueVO> searchCrTypCdList = this.splCrLimService.searchCrTypCdList();
		ModelAndView view = new ModelAndView("product/splCrLim/addSplCrLim");
		view.addObject("mfrId", mfrId);
		view.addObject("searchBuOrgList", this.doBuOrgCd(searchBuOrgList));
		view.addObject("searchCrTypCdList", searchCrTypCdList);
		view.addObject("splId",splId);
		return view;
	}
	//事业部处理
	public List<KeyValueVO> doBuOrgCd(List<KeyValueVO> listKeyValue) throws BaseException{
		List<KeyValueVO> listVo = new ArrayList<KeyValueVO>();
		String orgCd = CurrentThreadContext.getCurrentBuOrgCd();
		for(int i =0 ;i < listKeyValue.size(); i++){
			String splBuOrgCd = listKeyValue.get(i).getKey();
			if(StringUtils.isNotEmpty(splBuOrgCd) && splBuOrgCd.startsWith(orgCd)){
				listVo.add(listKeyValue.get(i));
			}
		}
		return listVo;
	}
	
	

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getSplById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("获取供应商数据,主键参数为空！")
					.setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		
		try {
			SplInfoVO vo = this.prdSplInfoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.newWebLogger("获取供应商数据不存在,ID:"+id)
						.setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			result.setData(vo);
			BaseLogUtils.newWebLogger("获取供应商数据成功,ID:"+id)
					.setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("获取供应商数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("获取供应商数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}
	
	
	/**
	 * 跳转供应商资料新增页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toSplFileAddPage.do", method = { RequestMethod.GET})
	public ModelAndView toSplFileAddPage(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");
		String isDetail = request.getParameter("isDetail");
		ModelAndView view = new ModelAndView("product/splInfo/splFileAdd");
		view.addObject("splId", splId);
		view.addObject("isDetail", isDetail);
		return view;
	}
	
	/**
	 * 保存供应商授信
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/addSplCrLim.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addSplCrLim(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String licNo = request.getParameter("licNo");//协议编号
		String splId = request.getParameter("splId");//供应商ID
		String startDt = request.getParameter("startDt");//开始时间
		String endDt = request.getParameter("endDt");//结束时间
		String lvl = request.getParameter("lvl");//星级
		String crAmt = request.getParameter("crAmt");//授信额
		String orgCd = request.getParameter("orgCd");//组织架构
		String orgDispNm = request.getParameter("orgDispNm");//组织架构名
		String crTypCd = request.getParameter("crTypCd");//授信类型
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(splId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("保存供应商授信 供应商ID为空")
					.setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		if(StringUtils.isEmpty(crAmt)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("授信额度不能为空，且不能为0")
					.setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		
		try {
			//SplInfoVO prdSplInfoVO = this.prdSplInfoService.checkSplExist(splNm, bizLicNo);
			SplCrLimDTO dto = new SplCrLimDTO();
			dto.setSplId(Long.valueOf(splId));
			double crAmtD = DecimalUtils.mul(Double.valueOf(crAmt), 1, 2);
			dto.setCrAmt(DecimalUtils.convertYuanToFen(crAmtD));
			if(StringUtils.isNotBlank(startDt)){
				dto.setStartDt(DateUtils.formatStringToDate(startDt, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotBlank(endDt)){
				dto.setEndDt(DateUtils.formatStringToDate(endDt, DateUtils.YYYY_MM_DD));
			}
			dto.setLvl(lvl);
			dto.setOrgCd(orgCd);
			dto.setOrgDispNm(orgDispNm);
			if(StringUtils.isNotBlank(crTypCd)){
				dto.setCrTypCd(Integer.valueOf(crTypCd));
			}
			dto.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			dto.setCrtTm(new Date());
			dto.setMdfTm(new Date());
			dto.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			dto.setIsHis(0);
			dto.setLicNo(licNo);
			Long id = this.splCrLimService.add(dto);
			if(null == id){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				BaseLogUtils.newWebLogger("供应商授信添加失败id="+id)
						.setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("保存供应商授信错误,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("保存供应商授信错误,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}
	/**
	 * 到供应商产品列表
	 */
	@RequestMapping(value = "/toPrjSplPrdListPage.do", method = { RequestMethod.GET})
	public ModelAndView toPrjSplPrdListPage(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");
		ModelAndView view = new ModelAndView("product/splCrLim/prjSplCrLimPrdList");
		view.addObject("prjId", prjId);
		return view;
	}
	/**
	 * 到供应商产品列表（根据付款信息id查询）
	 */
	@RequestMapping(value = "/toPrjSplPrdListPageByCapId.do", method = { RequestMethod.GET})
	public ModelAndView toPrjSplPrdListPageByCapId(HttpServletRequest request, HttpServletResponse response)throws BaseException {
		String capPayId = request.getParameter("capPayId");
		ModelAndView view = new ModelAndView("product/splCrLim/prjSplCrLimPrdList");
		
		if(StringUtils.isNotEmpty(capPayId)){
			CapPayInfoVO vo = this.capPayInfoService.selectById(Long.valueOf(capPayId));
			if(vo != null){
				view.addObject("prjId", vo.getPrjId());
				view.addObject("paySchId", vo.getPaySchId());
			}
		}
		return view;
	}
	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/prjSplPrdInitList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object prjSplPrdInitList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prjId = request.getParameter("prjId");
		String paySchId = request.getParameter("paySchId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjPrdBscInfoQueryCondition qc = new PrjPrdBscInfoQueryCondition();
		if(StringUtils.isNotBlank(prjId)){
			qc.setPrjId(Long.valueOf(prjId));
		}else{
			//return null;
		}
		if(StringUtils.isNotBlank(paySchId)){
			qc.setPaySchId(Long.valueOf(paySchId));
		}
		page.setCondition(qc);
		//Pager pager = this.prjPrdBscInfoService.searchListPage(page);
		Pager pager = this.splCrLimService.serchPrjSplPrdListPage(page);
		ListPageVO<PrjPrdBscInfoVO> listPage = new ListPageVO<PrjPrdBscInfoVO>((List<PrjPrdBscInfoVO>) pager.getResultList(), pager.getTotalCount());
		BaseLogUtils.newWebLogger("查询数据完成. DATA:" + JSONObject.toJSONString(page))
				.setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		return listPage;
	}
	
}

